-
Notifications
You must be signed in to change notification settings - Fork 7.8k
ethernet: stm32: add a alternative HAL_ETH_Init for V1 api #88483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
ethernet: stm32: add a alternative HAL_ETH_Init for V1 api #88483
Conversation
drivers/ethernet/eth_stm32_hal.c
Outdated
#if defined(CONFIG_ETH_STM32_HAL_API_V1) | ||
#define ETH_TIMEOUT_SWRESET 500U | ||
|
||
HAL_StatusTypeDef HAL_ETH_Init_alt(ETH_HandleTypeDef *heth) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is fine not using HAL_ETH_Init
, but please don't reimplement a HAL function and instead implement as much as possible a zephyr function:
Don't call it HAL_... but use zephyr function name
Don't return HAL type and take dev as argument.
Access ETH registers instead of (heth->Instance)->
....
Likely the 2 only pure HAL things that should remain are the State
and Lock
updates for further HAL operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tried it
1b6ba6d
to
d3d1df1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note. Why is eth_stm32_init_v1_api
happening at driver init. And the equivalent for v2
at api->init
(called by net core)?
v2 got moved there in #86621. the phy specific code from that than got removed in my #87593. Maybe it can be moved back? @marwaiehm-st what do you think, it was your pr? |
Yes, I moved the V2 to |
6f0eaf8
to
6fe7d22
Compare
added a commit to move it back |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for moving the v1
and v2
functions closer together. I have added another small hint. I am not familiar enough with the hal to review the eth_stm32_init_v1_api
. From what I can see looks good.
3cdcaca
to
0c4e0e1
Compare
ping @erwango |
@erwango please take a look |
I'll take time next week. Don't hesitate to ping me again. |
0c4e0e1
to
d83736d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments
drivers/ethernet/eth_stm32_hal.c
Outdated
/* Get the ETHERNET MACMIIAR value, this is responsible for mdio, so save it to restore it | ||
* later | ||
*/ | ||
tmpreg1 = (heth->Instance)->MACMIIAR; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can remove the parentheses.
Ditto at lines 880, 883 and 892.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
drivers/ethernet/eth_stm32_hal.c
Outdated
uint32_t tmpreg1 = 0U; | ||
|
||
if (heth->State == HAL_ETH_STATE_RESET) { | ||
/* Allocate lock resource and initialize it */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allocate
does not really apply here. Maybe simply remove the inline comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
drivers/ethernet/eth_stm32_hal.c
Outdated
if (WAIT_FOR((((heth->Instance)->DMABMR & ETH_DMABMR_SR) == (uint32_t)RESET), | ||
ETH_TIMEOUT_SWRESET, NULL) == false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could remove some parentheses (easier to read)
if (WAIT_FOR((((heth->Instance)->DMABMR & ETH_DMABMR_SR) == (uint32_t)RESET), | |
ETH_TIMEOUT_SWRESET, NULL) == false) { | |
if (!WAIT_FOR((heth->Instance->DMABMR & ETH_DMABMR_SR) == (uint32_t)RESET, | |
ETH_TIMEOUT_SWRESET, NULL)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
drivers/ethernet/eth_stm32_hal.c
Outdated
return -ETIMEDOUT; | ||
} | ||
|
||
(heth->Instance)->MACMIIAR = (uint32_t)tmpreg1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cast not needed, tmpreg1
is already of type uint32_t
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
d83736d
to
0cc6663
Compare
|
@erwango ping |
@marwaiehm-st Could you have a cross check and perform non regression on the changes ? |
drivers/ethernet/eth_stm32_hal.c
Outdated
heth->Instance->MACMIIAR = tmpreg1; | ||
|
||
/* Config MAC and DMA */ | ||
ETH_MACDMAConfig(heth, ETH_SUCCESS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function ETH_MACDMAConfig is defined as static in the STM32 HAL module.
static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth, uint32_t err);
Using ETH_MACDMAConfig here will cause a build error (undefined reference) because it is not accessible from other modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as changing the hal is now necessary, it was easier, to just remove the phy init and config code from the v1 HAL_ETH_Init
the phy is already configured by the phy driver in zephyr and we don't want to overwrite it in the HAL_ETH_Init function in the stm32 HAL. Signed-off-by: Fin Maaß <[email protected]>
0cc6663
to
b0d7838
Compare
The following west manifest projects have changed revision in this Pull Request:
⛔ DNM label due to: 1 project with PR revision Note: This message is automatically posted and updated by the Manifest GitHub Action. |
b0d7838
to
6df0e3f
Compare
|
add a alternative HAL_ETH_Init for V1 api without phy
configuration, as this is already been done outside of
the ethernet driver.
Signed-off-by: Fin Maaß [email protected]